﻿<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Menu.aspx.cs" Inherits="Menu" Title="Menu" %>

<asp:Content ID="Content1" ContentPlaceHolderID="PlaceHolder1" Runat="Server">
    <h1>DISHES</h1>
    <div>
    <center>
        <asp:ListView runat="server" ID="DishesListView" GroupItemCount="3" 
            onitemediting="DishesListView_ItemEditing" 
            onitemcanceling="DishesListView_ItemCanceling" 
            onitemupdating="DishesListView_ItemUpdating" DataSourceID="SqlDataSource1" 
            onitemdeleting="DishesListView_ItemDeleting" 
            onitemdatabound="DishesListView_ItemDataBound">
            <LayoutTemplate>
                <table cellpadding="5" cellspacing="9" runat="server" id="tblDishes" style="height:320px">
                    <tr runat="server" id="groupPlaceholder">
                    </tr>
                </table>
                <asp:DataPager runat="server" ID="DataPager" PageSize="6">
                    <Fields>    
                        <asp:NumericPagerField ButtonCount="3" PreviousPageText="<--" NextPageText="-->" />
                    </Fields>
                </asp:DataPager>
            </LayoutTemplate>
              <GroupTemplate>
                <tr runat="server" id="dishesRow" style="height:100px">
                  <td runat="server" id="itemPlaceholder">
                  </td>
                </tr>
              </GroupTemplate>
              <ItemTemplate>
                <td id="Td1" valign="top" align="center" style="width:300" runat="server">
                <asp:Label runat="server" ID="lblID" Text='<%#Eval("ID") %>' Visible="false" />
                  <asp:Label Font-Bold="true" Font-Size="9" ForeColor="Red" ID="dishName" runat="server" Text='<%#Eval("Name") %>' />
                  <br />
                  <asp:Label Font-Size="8" ForeColor="Red" ID="Label1" runat="server" Text='<%#Eval("Price") %>' />
                  <br />
                  <asp:Image ID="dishImage" runat="server"
                       ImageUrl='<%#"~/Images/" + Eval("Image") %>'
                       Height="100" Width="100"/> 
                       <br />
                  <asp:LinkButton Height="18"  ID="lbnAddtoMenu" runat="server" Text="Add to menu" CommandArgument='<%#Eval("ID") %>' OnCommand="lbnAddtoMenu_OnClick" />
                  <br />
                  <div runat="server" id="divAdminOnly"><asp:LinkButton runat="server" ID="lbnEdit" CommandName="edit" Text="Edit" />
                 <asp:LinkButton runat="server" ID="lbnDelete" CommandName="delete" Text="Delete" /></div>
                 
                </td>
              </ItemTemplate>
              <EditItemTemplate>
                <td id="Td1" valign="top" align="left" style="width:300" runat="server">
                <table>
                    <asp:Label runat="server" ID="lblID" Text='<%#Eval("ID") %>' Visible="false" />
                    <tr>
                        <td>Dish Name :</td>
                        <td><asp:TextBox ID="txtDishName" Width="100" runat="server" Text='<%#Bind("Name") %>' /></td>
                    </tr>
                    <tr>
                        <td>Price :</td>
                        <td><asp:TextBox ID="txtPrice" Width="100" runat="server" Text='<%#Bind("Price") %>' /></td>
                    </tr>
                    <tr>
                        <td>Image :</td>
                        <td><asp:TextBox ID="txtImage" Width="100" runat="server" Text='<%#Bind("Image") %>' /></td>
                    </tr>
                    <tr>
                        <td colspan="2" align="center"><asp:LinkButton runat="server" ID="lbnUpdate" CommandName="update" Text="Update" /><asp:LinkButton runat="server" ID="lbnCancel" CommandName="cancel" Text="Cancel" /></td>
                    </tr>
                </table>
                   
                   
                  
                </td>
              </EditItemTemplate>
</asp:ListView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="Data Source=localhost;Initial Catalog=RestaurantBooking;Persist Security Info=True;User ID=admin;Password=123456" 
            ProviderName="System.Data.SqlClient" 
            SelectCommand="SELECT * FROM [Dishes]" 
            DeleteCommand="DELETE FROM [Dishes] WHERE [ID] = @ID" 
            InsertCommand="INSERT INTO [Dishes] ([Name], [Image], [Price]) VALUES (@Name, @Image, @Price)" 
            UpdateCommand="UPDATE [Dishes] SET [Name] = @Name, [Image] = @Image, [Price] = @Price WHERE [ID] = @ID">
            <DeleteParameters>
                <asp:Parameter Name="ID" Type="Int32" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="Name" Type="String" />
                <asp:Parameter Name="Image" Type="String" />
                <asp:Parameter Name="Price" Type="Int32" />
                <asp:Parameter Name="ID" Type="Int32" />
            </UpdateParameters>
            <InsertParameters>
                <asp:Parameter Name="Name" Type="String" />
                <asp:Parameter Name="Image" Type="String" />
                <asp:Parameter Name="Price" Type="Int32" />
            </InsertParameters>
        </asp:SqlDataSource>
</center>
    </div>
    
    <hr />
    
    <h1>SAMPLE MENU</h1>
    <div>
    
    </div>
</asp:Content>

